package org.leon.builder;

import org.dom4j.DocumentException;
import org.leon.Executor;
import org.leon.SimpleExecutor;
import org.leon.factory.DefaultSqlSessionFactory;
import org.leon.factory.SqlSessionFactory;
import org.leon.pojo.Configuration;

import java.beans.PropertyVetoException;
import java.io.InputStream;

/**
 * Created by leon.L on 2019/12/19.
 * Desc :
 */
public class SqlSessionFactoryBuilder {

    /**
     * 构建工厂的入口，让用户传入配置文件的文件流
     * @param inputStream
     * @return
     */
    public SqlSessionFactory build(InputStream inputStream) throws PropertyVetoException, DocumentException {
        XmlConfigurationBuilder xmlHelper = new XmlConfigurationBuilder();
        // 读取数据源信息xml为Configuration对象
        Configuration configuration = xmlHelper.parseXml(inputStream);

        // 声明一个执行器
        Executor executor = new SimpleExecutor();

        return new DefaultSqlSessionFactory(configuration, executor);
    }


}
